//
//  ForgetPwdViewController.m
//  WaywardPoint_Code
//
//  Created by 韩盼盼 on 15/8/26.
//  Copyright (c) 2015年 易网新科技. All rights reserved.
//

#import "ForgetPwdViewController.h"

#import "LoginViewController.h"

@interface ForgetPwdViewController ()<UITextFieldDelegate,HeadBackView>
{
    UIButton *goBackBtn;
    /** 获取手机验证码btn*/
    UIButton *getUserPre;
    //提示label
    UILabel *tishiLab;

    //验证页面
    UIView *VerifyView;
    NSTimer *_coolDownTimer;
    int starTime;
    int _stepTime;
    UIButton *againBtn;
    //    NSString *strtime;
    UITextField *userNo;
    
    //重置密码
    UIView *againsetView;
    UITextField *userpassword;
    UITextField *Confirmpwd;
    UIButton *againsetBtn;
    
}

@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,copy)NSString *strtime;
@end

@implementation ForgetPwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=RXDColor(251, 251, 251);
    
    self.title = @"重置密码";
    
    [self showUI];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden=YES;
}
- (void)showUI
{
    UIView *contentView=[[UIView alloc]initWithFrame:CGRectMake(0, 65, ScreenW, ScreenH-20)];
    contentView.backgroundColor=RXDColor(251, 251, 251);
    
    [self.view addSubview:contentView];
    
    UILabel *text=[[UILabel alloc]initWithFrame:CGRectMake(20, 20, ScreenW-40, 15)];
    text.text=@"请确保您的手机畅通，用于接收验证码短信";
    text.font=[UIFont systemFontOfSize:Font_SIZE_18];
    [contentView addSubview:text];
    text.textColor = COLOT_TEXTGRAY;
    //    num=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 120, 30)];
    //    num.text=@"+86";
    //    num.font=[UIFont systemFontOfSize:18 ];
    UIView *spaceview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 45)];
    
    self.userIphone=[[UITextField alloc]initWithFrame:CGRectMake(20, text.y+30, contentView.width-40, 70*PROPORTION_WIDTH)];
    self.userIphone.backgroundColor=[UIColor whiteColor];
    self.userIphone.tag=130;
    self.userIphone.leftView=spaceview;
    self.userIphone.leftViewMode=UITextFieldViewModeAlways;
    self.userIphone.placeholder=@"请输入您的手机号";
    self.userIphone.font = [UIFont systemFontOfSize:Font_SIZE_18];
    self.userIphone.keyboardType=UIKeyboardTypeNumberPad;
    [self.userIphone addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    getUserPre.userInteractionEnabled=YES;
    //    self.userIphone.leftView=num;
    //    self.userIphone.leftViewMode = UITextFieldViewModeAlways;
    tishiLab=[[UILabel alloc]initWithFrame:CGRectMake(20, self.userIphone.y+50,self.userIphone.width, 10)];
    tishiLab.hidden=YES;
    
    tishiLab.font=[UIFont boldSystemFontOfSize:13];
    tishiLab.textColor=RXDColor(223, 56, 109);
    [contentView addSubview:tishiLab];
    
    [contentView addSubview:self.userIphone];
    getUserPre=[[UIButton alloc]initWithFrame:CGRectMake(20, self.userIphone.bottom+60*PROPORTION_WIDTH, self.userIphone.width, 95*PROPORTION_WIDTH)];
    [getUserPre setTitle:@"获取手机验证码" forState:UIControlStateNormal];
    [getUserPre setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [getUserPre addTarget:self action:@selector(forgetnextstep) forControlEvents:UIControlEventTouchUpInside];
    if (_usertel.length>0) {
        getUserPre.backgroundColor=RXDColor(223, 56, 109);
    }
    else
    {
        getUserPre.backgroundColor=RXDColor(221, 221, 221);
        getUserPre.userInteractionEnabled=NO;
    }
    
    getUserPre.titleLabel.font=[UIFont boldSystemFontOfSize:15];
    [contentView addSubview:getUserPre];
}
- (void)btnback {
    
    [self.navigationController popViewControllerAnimated:YES];
//    [self popToView];
}

#pragma mark - 监听textfiled的输入


- (void)textFieldDidChange:(UITextField *)textField
{
    switch (textField.tag) {
        case 130:
            if (textField == self.userIphone) {
                
                if (textField.text.length > 10) {
                    textField.text = [textField.text substringToIndex:11];
                    getUserPre.backgroundColor=RXDColor(223, 56, 109);
                    getUserPre.userInteractionEnabled=YES;
                }
                else
                {
                    getUserPre.backgroundColor=RXDColor(221, 221, 221);
                    getUserPre.userInteractionEnabled=NO;
                    
                }
            }

            break;
            case 131:
            if (textField == userNo) {
                if (textField.text.length > 5) {
                    textField.text = [textField.text substringToIndex:6];
                    getUserPre.backgroundColor=RXDColor(223, 56, 109);
                    getUserPre.userInteractionEnabled=YES;
                }
                else
                {
                    getUserPre.backgroundColor=RXDColor(221, 221, 221);
                    getUserPre.userInteractionEnabled=NO;
                    tishiLab.hidden=YES;
                    
                }
            }

            break;
            case 132:
                if (textField==Confirmpwd)
                {
                    if (textField.text !=nil &&userpassword.text!=nil)
                    {
                        tishiLab.hidden=YES;
                        
                        if (![textField.text isEqualToString:Confirmpwd.text]) {
                            againsetBtn.backgroundColor = RXDColor(221, 221, 221);
                            againsetBtn.userInteractionEnabled=NO;
                            tishiLab.hidden=NO;
                            tishiLab.text = @"两次密码不一致";
                        }
                        else
                        {
                            tishiLab.hidden=YES;
                            againsetBtn.backgroundColor = RXDColor(223, 56, 109);                       againsetBtn.userInteractionEnabled=YES;
                            
                        }
                    }
                    else
                    {
                        tishiLab.hidden=NO;
                        againsetBtn.backgroundColor=RXDColor(221, 221, 221);
                        againsetBtn.userInteractionEnabled=NO;
                        
                    }
                }
            break;
            
        case 133:
            if (textField==userpassword)
            {
                
                if (textField.text.length>5)
                {
                    tishiLab.hidden = YES;
                    
                    if (textField.text.length>5&&Confirmpwd.text.length>5) {
                        if (![textField.text isEqualToString:Confirmpwd.text]) {
                            againsetBtn.backgroundColor = RXDColor(221, 221, 221);
                            againsetBtn.userInteractionEnabled=NO;
                            tishiLab.hidden=NO;
                            tishiLab.text = @"两次密码不一致";
                        }
                        else
                        {
                            tishiLab.hidden=YES;
                            againsetBtn.backgroundColor = RXDColor(223, 56, 109);                       againsetBtn.userInteractionEnabled=YES;

                        }
                    }
                }
                else
                {
                    tishiLab.hidden=NO;
                    tishiLab.text = @"密码不能低于6位";
                    againsetBtn.backgroundColor = RXDColor(221, 221, 221);
                    againsetBtn.userInteractionEnabled=NO;
                    
                }
            }
            break;

            
        default:
            break;
    }
}

- (void)forgetnextstep
{
    NSString *telstr = self.userIphone.text;
    //验证号码是否为正确手机号
    if ([self checkTelNumber:telstr]) {
        [self loadData];
        [self startTime];
        starTime=60;
    }
    else
    {
        tishiLab.hidden=NO;
        tishiLab.text=@"号码输入有误，请检查！";
        
    }

}

- (void)loadData
{
    
    //GET
    //请求管理者
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    mgr.responseSerializer = [AFJSONResponseSerializer serializer];
    mgr.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@"text/html"];
    NSString *urlStr=[NSString stringWithFormat:@"%@member/mobile/check?mobile=%@",MRAPI,self.userIphone.text];
   
    //发送请求
    [mgr GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dict=responseObject;
        NSString *str =[dict[@"status"] stringValue];
        _verifyInfo=str;
        NSLog(@"loadData====%@",str);
        
        NSLog(@"_verifyInfo++++++++%@",_verifyInfo);
        //验证手机是否被注册
        
        if ([ _verifyInfo isEqualToString:@"1"]) {
            
            [self setupverifyView];
            
        }
        else
        {
//            [MBProgressHUD showError:@"该手机还没有注册！"];
            tishiLab.hidden=NO;
            tishiLab.text=@"该手机还没有注册！";
            
            return;
        }
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [MBProgressHUD showError:@"请求服务器失败"];
     }];
}

//发送短信验证码http://renxingdian.ketao.com/api/captcha
- (void)getcaptchamsg
{
    
    NSString *url =[NSString stringWithFormat:@"%@captcha",MRAPI];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];//设置相应内容类型
    // 2.封装参数(这个字典只能放非文件参数)
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"mobile"] = self.userIphone.text;
    params[@"type"]=[NSNumber numberWithInt:3];
    
    [manager POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [MBProgressHUD hideHUD];
               NSString *error=responseObject[@"error"];
        if (![error isEqualToString:@""]) {
            [MBProgressHUD showError:error];
            
        } else {
            self.strRandomtext=[NSString stringWithFormat:@"%@",responseObject[@"captcha"]];
            NSLog(@"wangjimima%@",self.strRandomtext);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    }];
}

#pragma mark -  验证码页面

-(void)setupverifyView
{
    VerifyView=[[UIView alloc]init];
    VerifyView.frame=self.view.frame;
    [self.view addSubview:VerifyView];
    
    UIView *headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 20, ScreenW, 50)];
    headerView.backgroundColor=RXDColor(223, 56, 109);
    [VerifyView addSubview:headerView];
    
    goBackBtn=[[UIButton alloc]initWithFrame:CGRectMake(5, 5, 40, 40)];
    [goBackBtn setImage:[UIImage imageNamed:@"return_2"] forState:UIControlStateNormal];
    
    [goBackBtn addTarget:self action:@selector(verifyBackBtnEvent) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:goBackBtn];
    
    UILabel *setlab=[[UILabel alloc]initWithFrame:CGRectMake(goBackBtn.width, 10, 120, 30)];
    setlab.text=@"填写验证码";
    setlab.textColor=[UIColor whiteColor];
    setlab.font=[UIFont boldSystemFontOfSize:18];
    [headerView addSubview:setlab];
    [self verifyViewshowUI];
}

- (void)verifyViewshowUI
{
    UIView *contentView=[[UIView alloc]initWithFrame:CGRectMake(0,64, ScreenW, ScreenH-20)];
    contentView.backgroundColor = RXDColor(251, 251, 251);
    
    [VerifyView addSubview:contentView];
    
    UILabel *titleLa1=[[UILabel alloc]initWithFrame:CGRectMake(15, 20, 80, 20)];
    titleLa1.text=@"验证码已发往";
    titleLa1.font=[UIFont systemFontOfSize:13];
    [contentView addSubview:titleLa1];
    _titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(titleLa1.x+titleLa1.width+2, 20, 130, 20)];
    _titleLabel.text=[NSString stringWithFormat:@"%@,",self.userIphone.text];
    _titleLabel.textColor=RXDColor(223, 56, 109);
    _titleLabel.font=[UIFont systemFontOfSize:18];
    [contentView addSubview:_titleLabel];
    UILabel *titleLa2=[[UILabel alloc]initWithFrame:CGRectMake(_titleLabel.x+_titleLabel.width+2, 20, 50, 20)];
    titleLa2.font=[UIFont systemFontOfSize:13];
    titleLa2.text=@"请等候";
    [contentView addSubview:titleLa2];
    
    userNo=[[UITextField alloc]initWithFrame:CGRectMake(20, _titleLabel.y+40, contentView.width*0.5+20, 40)];
    userNo.font=[UIFont systemFontOfSize:18];
    userNo.leftView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 40)];
    userNo.leftViewMode=UITextFieldViewModeAlways;
    userNo.backgroundColor=[UIColor whiteColor];
    userNo.placeholder=@"请输入验证码";
    userNo.tag=131;
    userNo.keyboardType=UIKeyboardTypeNumberPad;
    [userNo addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    userNo.userInteractionEnabled=YES;
    
    userNo.leftViewMode = UITextFieldViewModeAlways;
    
    againBtn=[[UIButton alloc]initWithFrame:CGRectMake(userNo.width+40, userNo.y, userNo.width*0.5-10, 40)];
    againBtn.backgroundColor=RXDColor(223, 56, 109);
    [againBtn setTitle:@"发送中" forState:UIControlStateNormal];
    againBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [againBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [againBtn addTarget:self action:@selector(startTime) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:againBtn];
    
    [contentView addSubview:userNo];
    
    tishiLab=[[UILabel alloc]initWithFrame:CGRectMake(20, userNo.y+55, userNo.width, 10)];
    tishiLab.hidden=YES;
    //    tishiLab.text=@"测试";
    tishiLab.font=[UIFont boldSystemFontOfSize:13];
    tishiLab.textColor=RXDColor(223, 56, 109);
    [contentView addSubview:tishiLab];
    
    getUserPre=[[UIButton alloc]initWithFrame:CGRectMake(20, userNo.y+85, contentView.width-40, userNo.height)];
    [getUserPre setTitle:@"下一步" forState:UIControlStateNormal];
    [getUserPre addTarget:self action:@selector(verifynextstep) forControlEvents:UIControlEventTouchUpInside];
    [getUserPre setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    getUserPre.titleLabel.font=[UIFont boldSystemFontOfSize:15];
    getUserPre.backgroundColor = COLOR_UNBUTTON;
    getUserPre.userInteractionEnabled=NO;
    
    [contentView addSubview:getUserPre];
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
- (void)verifynextstep
{
    if ([userNo.text isEqualToString:self.strRandomtext])
    {
        [self setupAgainsetView];
        [VerifyView removeFromSuperview];
    }
    else
    {
        tishiLab.hidden=NO;
        tishiLab.text=@"验证码输入错误！";
    }
    
}
- (void)verifyBackBtnEvent
{
    [VerifyView removeFromSuperview];
    starTime=0;
}

#pragma mark - 倒计时

- (void)startTime
{
    [self getcaptchamsg];
    starTime=60;
//    __block int timeout=60; //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        if(starTime<=0){ //倒计时结束，关闭
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                [againBtn setTitle:@"重新发送" forState:UIControlStateNormal];
                againBtn.userInteractionEnabled = YES;
                againBtn.backgroundColor=RXDColor(223, 56, 109);
                
                
            });
        }else{
            //            int minutes = timeout / 60;
            //            int seconds = timeout % 60;
            NSString *strTime = [NSString stringWithFormat:@"%.2d", starTime];
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
            [againBtn setTitle:[NSString stringWithFormat:@"(%@)秒后\n重新发送",strTime] forState:UIControlStateNormal];
                againBtn.backgroundColor=[UIColor grayColor];
                againBtn.titleLabel.numberOfLines=2;
                againBtn.userInteractionEnabled = NO;
                
            });
            starTime--;
            
        }
    });
    dispatch_resume(_timer);
}

#pragma mark - 重设密码
- (void)setupAgainsetView
{
    againsetView=[[UIView alloc]init];
    againsetView.frame=self.view.frame;
    [self.view addSubview:againsetView];
    UIView *headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 20, ScreenW, 40)];
    headerView.backgroundColor=RXDColor(223, 56, 109);
    [againsetView addSubview:headerView];
    
    goBackBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 2.5, 35, 35)];
    [goBackBtn setImage:[UIImage imageNamed:@"return_2"] forState:UIControlStateNormal];
    
    [goBackBtn addTarget:self action:@selector(againsetViewEvent) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:goBackBtn];
    
    UILabel *setlab=[[UILabel alloc]initWithFrame:CGRectMake(goBackBtn.width, 10, 120, 20)];
    setlab.text=@"重置密码";
    setlab.textColor=[UIColor whiteColor];
    setlab.font=[UIFont boldSystemFontOfSize:18];
    [headerView addSubview:setlab];
    [self againsetShowUI];
}

- (void)againsetShowUI
{
    UIView *contentView=[[UIView alloc]initWithFrame:CGRectMake(0, 65, ScreenW, ScreenH-20)];
    contentView.backgroundColor=RXDColor(251, 251, 251);
    
    [againsetView addSubview:contentView];
    
    
    UIImageView *userright=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    userright.image=[UIImage imageNamed:@"login_pwd"];
    
    userpassword=[[UITextField alloc]initWithFrame:CGRectMake(20, 10, contentView.width-40, 35)];
    userpassword.placeholder=@"请设置登录密码";
    
    userpassword.secureTextEntry = YES;
    userpassword.backgroundColor=[UIColor whiteColor];
    userpassword.rightView=userright;
    userpassword.tag = 133;
    
    userpassword.rightViewMode = UITextFieldViewModeAlways;
    [contentView addSubview:userpassword];
    
    userpassword.delegate = self;
    userpassword.returnKeyType = UIReturnKeyNext;
    
     [userpassword addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    
    UIImageView *pwdright=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    pwdright.image=[UIImage imageNamed:@"login_pwd"];
    
    Confirmpwd=[[UITextField alloc]initWithFrame:CGRectMake(20, userpassword.y+45, contentView.width-40, 35)];
    Confirmpwd.placeholder=@"请确认登录密码";
    Confirmpwd.backgroundColor=[UIColor whiteColor];
    Confirmpwd.secureTextEntry = YES;
    Confirmpwd.rightView=pwdright;
    Confirmpwd.tag=132;
    Confirmpwd.returnKeyType=UIReturnKeyDone;
    Confirmpwd.delegate=self;
    Confirmpwd.rightViewMode = UITextFieldViewModeAlways;
    [contentView addSubview:Confirmpwd];
    [Confirmpwd addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    tishiLab=[[UILabel alloc]initWithFrame:CGRectMake(20, Confirmpwd.y+40, ScreenW*0.5, 10)];
    tishiLab.textColor=[UIColor redColor];
    tishiLab.font=[UIFont systemFontOfSize:12];
    tishiLab.hidden=YES;
    [contentView addSubview:tishiLab];
    
    againsetBtn=[[UIButton alloc]initWithFrame:CGRectMake(20, Confirmpwd.y+65, contentView.width-40, userpassword.height)];
    [againsetBtn setTitle:@"确  定" forState:UIControlStateNormal];
    [againsetBtn addTarget:self action:@selector(againsetEvent) forControlEvents:UIControlEventTouchUpInside];
    [againsetBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    againsetBtn.titleLabel.font=[UIFont boldSystemFontOfSize:15];
    againsetBtn.backgroundColor=RXDColor(221, 221, 221);
    [contentView addSubview:againsetBtn];
}

- (void)againsetViewEvent
{
    [againsetView removeFromSuperview];
    starTime=0;
}

/**这个是 textfield*/
- (BOOL)textFieldShouldReturn:(UITextField*)textField {
    
    BOOL retValue = NO;
    // see if we're on the username or password fields
    if (textField == userpassword)//当是 “手机号码”输入框时
    {
        if ([textField.text length]  != 0)//输入的号码完整时
        {
            [Confirmpwd becomeFirstResponder];// “会员密码”输入框 作为 键盘的第一 响应者，光标 进入此输入框中
            retValue = YES;
        }
    }
    else
    {
        [Confirmpwd resignFirstResponder];//如果 现在 是 第二个输入框，那么 键盘 隐藏
        [self againsetEvent];
    }
    
    return retValue;
    
    //返回值为NO，即 忽略 按下此键；若返回为YES则 认为 用户按下了此键，并去调用TextFieldDoneEditint方法，在此方法中，你可以继续 写下 你想做的事
}

/**修改的网络请求*/
- (void)againsetEvent
{
    againsetBtn.userInteractionEnabled=NO;
    if ([userpassword.text isEqualToString:Confirmpwd.text]) {
        tishiLab.hidden=YES;
    
        Reachability *reach = [Reachability reachabilityForInternetConnection];
        NetworkStatus status = [reach currentReachabilityStatus];
        NSString *urlstr=[NSString stringWithFormat:@"%@member/password/findbycaptcha",MRAPI];
        NSLog(@"%@",urlstr);
        
        if (![UIView NetFromStatus:status]) {
            
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            [UIView showAlertMsg:@"网络连接已断开" andShowBgColor:[UIColor blackColor] andLabelTectColor:[UIColor whiteColor]];
            return;
        }else
        {
            NSMutableDictionary *params = [NSMutableDictionary dictionary];
            params[@"mobile"] = self.userIphone.text;
            params[@"password"] = userpassword.text;
            params[@"captcha"]=self.strRandomtext;
            
            [[HttpRequest shardWebUtil]postNetworkRequestURLString:urlstr andParas:params andTransferGottenData:^(id obj, NSError *error) {
                againsetBtn.userInteractionEnabled=YES;

                if (error == nil) {
                    NSString *error = obj[@"error"];
                    if (![error isEqualToString:@""]) {
                        [UIView showAlertMsg:@"修改失败" andShowBgColor:[UIColor blackColor] andLabelTectColor:[UIColor whiteColor]];
                        
                    } else {
                        [UIView showAlertMsg:@"修改成功" andShowBgColor:[UIColor blackColor] andLabelTectColor:[UIColor whiteColor]];
                        [againsetView  removeFromSuperview];
                    
                        //跳转到相应的页面
                        for (UIViewController *temp in self.navigationController.viewControllers) {
                            
                            if ([temp isKindOfClass:[LoginViewController class]]) {
                                [self.navigationController popToViewController:temp animated:YES];
                            }
                        }
                    }
                }
                else
                {
                    [UIView showAlertMsg:@"网络请求超时" andShowBgColor:[UIColor blackColor] andLabelTectColor:[UIColor whiteColor]];
                }
            }];
        }
    }
    else
    {
        tishiLab.hidden=NO;
        tishiLab.text=@"两次密码输入不一致！";
    }
}


#pragma mark === 随机数
- (NSString *)strRandom
{
    NSString *strRandom = @"";
    for(int i=0; i<6; i++)
        
    {
        int a=arc4random() % 9+1;
        strRandom = [ strRandom stringByAppendingFormat:@"%i",a ];
    }
   
    return strRandom;
}

- (BOOL)checkTelNumber:(NSString *) telNumber
{
    NSString *pattern = @"^1+[3578]+\\d{9}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:telNumber];
    return isMatch;
}
///// 手机号码的有效性判断
//检测是否是手机号码
- (BOOL)isMobileNumber:(NSString *)mobileNum
{
    /**
     * 手机号码
     * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     * 联通：130,131,132,152,155,156,185,186
     * 电信：133,1349,153,180,189
     */
    NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
    /**
     10         * 中国移动：China Mobile
     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     12         */
    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
    /**
     15         * 中国联通：China Unicom
     16         * 130,131,132,152,155,156,185,186
     17         */
    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
    /**
     20         * 中国电信：China Telecom
     21         * 133,1349,153,180,189
     22         */
    NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    /**
     25         * 大陆地区固话及小灵通
     26         * 区号：010,020,021,022,023,024,025,027,028,029
     27         * 号码：七位或八位
     28         */
    // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    
    if (([regextestmobile evaluateWithObject:mobileNum] == YES)
        || ([regextestcm evaluateWithObject:mobileNum] == YES)
        || ([regextestct evaluateWithObject:mobileNum] == YES)
        || ([regextestcu evaluateWithObject:mobileNum] == YES))
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

@end
